function drawPlanet (name,color,x,y,r) {
    with(name) {
	// each segment is 45 degrees, so convert to radians.
	var theta = (45/180)*Math.PI; 
	// this gets the radius of the control point
	var ctrlRadius = r/Math.cos(theta/2);  
	//we start the circle on the far right side.
	moveTo(x+r, y); 
	// start drawing at angle 0;
	var angle = 0; 
	// this loop draws the circle in 8 segments
	beginFill(color,100);
	for(var i=0; i<8; i++){
	    angle += theta;
	    // increment our angles
	    var angleMid = angle-(theta/2);
	    // calculate our control point
	    var cx = x+Math.cos(angleMid)*(ctrlRadius);
	    var cy = y+Math.sin(angleMid)*(ctrlRadius);
	    // calculate our end point
	    var px = x+Math.cos(angle)*r;
	    var py = y+Math.sin(angle)*r;
	    // draw the circle segment
	    curveTo(cx, cy, px, py);
	}
	endFill();
    }
}
// Function to draw a Planet with a gradient shading appropriate 
//    for the planet's position.
function drawplanetMask (name,pos,r,color){
    with(name) {
	var tv = Math.atan(pos[1]/pos[0]);
	var pv = Math.acos(pos[2]/Math.sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]));
	var theta = (45/180)*Math.PI;
	var ctrlRadius = r/Math.cos(theta/2);
	var t = new TransformMatrix();
	var scalefac=5;
	t.scale(r*scalefac*Math.cos(pv)+1,r*scalefac);
	linestyle(0,0x000000,0);
	var alphas = [ 100, 100];
	var ratios = [ 0x60, 0x90 ];
	if(pv <= Math.PI/2){
	    //start at top of circle
	    var angle = Math.PI/2;
	    beginFill(color,100);
	    moveTo(0,-r);
	    lineTo(0,r);
	    for(var i=0; i<=3; i++){
		angle += theta;
		var angleMid = angle-(theta/2);
		// calculate our control point
		var cx = x+Math.cos(angleMid)*(ctrlRadius);
		var cy = y+Math.sin(angleMid)*(ctrlRadius);
		// calculate our end point
		var px = x+Math.cos(angle)*r;
		var py = y+Math.sin(angle)*r;
		// draw the circle segment
		curveTo(cx, cy, px, py);
	    }
	    endFill();
	    var colors = [ color, 0x000000];
	    beginGradientFill("radial", colors, alphas, ratios, t);
	    moveTo(0,r);
	    lineTo(0,-r);
	    angle=-Math.PI/2;
	    for(var i=0; i<=3; i++){
		angle += theta;
		var angleMid = angle-(theta/2);
		// calculate our control point
		var cx = x+Math.cos(angleMid)*(ctrlRadius);
		var cy = y+Math.sin(angleMid)*(ctrlRadius);
		// calculate our end point
		var px = x+Math.cos(angle)*r;
		var py = y+Math.sin(angle)*r;
		// draw the circle segment
		curveTo(cx, cy, px, py);
	    }
	    endFill();
	}
	else {
	    var angle = Math.PI/2;
	    var colors = [0x000000, color];
	    beginGradientFill("radial", colors, alphas, ratios, t);
	    moveTo(0,-r);
	    lineTo(0,r);
	    for(var i=0; i<=3; i++){
		angle += theta;
		var angleMid = angle-(theta/2);
		// calculate our control point
		var cx = x+Math.cos(angleMid)*(ctrlRadius);
		var cy = y+Math.sin(angleMid)*(ctrlRadius);
		// calculate our end point
		var px = x+Math.cos(angle)*r;
		var py = y+Math.sin(angle)*r;
		// draw the circle segment
		curveTo(cx, cy, px, py);
	    }
	    endFill();	    
	    angle = -Math.PI/2;
	    beginFill(0x000000,100);
	    moveTo(0,r);
	    lineTo(0,-r);
	    for(var i=0; i<=3; i++){
		angle += theta;
		var angleMid = angle-(theta/2);
		// calculate our control point
		var cx = x+Math.cos(angleMid)*(ctrlRadius);
		var cy = y+Math.sin(angleMid)*(ctrlRadius);
		// calculate our end point
		var px = x+Math.cos(angle)*r;
		var py = y+Math.sin(angle)*r;
		// draw the circle segment
		curveTo(cx, cy, px, py);
	    }
	    endFill();
	}
    }
    if(pos[0]<=0){tv += Math.PI};
    name._rotation = tv*180/Math.PI;
}
function removeAxes (){
    _root["xaxisMC"].removeMovieClip();
    _root["yaxisMC"].removeMovieClip();
    _root["zaxisMC"].removeMovieClip();
}
function drawAxes (theta,phi){
    var tmpxaxis=_root.createEmptyMovieClip("xaxisMC",_root.depth++);
    var tmpyaxis=_root.createEmptyMovieClip("yaxisMC",_root.depth++);
    var tmpzaxis=_root.createEmptyMovieClip("zaxisMC",_root.depth++);
    var newxvec=rotate(100,0,0,theta,phi);
    var newyvec=rotate(0,100,0,theta,phi);
    var newzvec=rotate(0,0,100,theta,phi);
    var newxpos=project(d,newxvec,1);
    var newypos=project(d,newyvec,1);
    var newzpos=project(d,newzvec,1);
    with(tmpxaxis){
	linestyle(2,0x000000,100);
	swapDepth(-newxvec[2]);
	moveto(xorig,xorig);
	lineto(newxpos[0]+xorig,newxpos[1]+yorig);
    }
    with(tmpyaxis){
	linestyle(2,0x000000,100);
	swapDepth(-newyvec[2]);
	moveto(xorig,yorig);
	lineto(newypos[0]+xorig,newypos[1]+yorig);
    }
    with(tmpzaxis){
	linestyle(2,0x000000,100);
	swapDepth(-newzvec[2]);
	moveto(xorig,yorig);
	lineto(newzpos[0]+xorig,newzpos[1]+yorig);
    }
}
